package Frame.screen;

import FCRendering.FCRMaster;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.ImageObserver;
import java.util.concurrent.CopyOnWriteArrayList;

public abstract class IScreen implements ImageObserver,IRListener {

    private FCRMaster mfcrMaster;

    private CopyOnWriteArrayList<IScreen> childScreens = new CopyOnWriteArrayList<>();

    @Override
    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
        return mfcrMaster.imageUpdate(img, infoflags, x, y, width, height);
    }

    public void paintComponent(Graphics g, FCRMaster fcrMaster) {
        mfcrMaster = fcrMaster;
        dispatchPaintComponent(g, fcrMaster);
        for (IScreen iScreen : childScreens) {
            iScreen.paintComponent(g, fcrMaster);
        }
    }

    public abstract void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster);
    //在FCRMaster被调用链 setbound后调用，初始化Fonts
    protected abstract void setBounds();

    public void addChildScreenByOrder(IScreen screen) {
        if (!childScreens.contains(screen)) {
            childScreens.add(screen);
        }
    }

    public void removeChildScreen(IScreen screen) {
        if (childScreens.contains(screen)) {
            childScreens.remove(screen);
        }
    }

    public void dipatchSetBounds(){
        setBounds();
        for (IScreen iScreen : childScreens) {
            iScreen.setBounds();
        }
    }
    public void listen_mouse_click_game(MouseEvent g){

    }
    public void listen_mouse_move_game(MouseEvent g){

    }
    public void listen_mouse_release_game(MouseEvent g){

    }

    public void listen_mouse_press_game(MouseEvent g) {

    }

    public void listen_key_press_game(String e) {

    }
}
